package com.xjzd.jvm;

class Constants {
    static final int COMPILE_TIME_CONSTANT = 100;  // 编译期常量
    static final String MESSAGE = "Hello World";   // 编译期常量
    static final String osName = System.getProperty("os.name");  // 运行期常量会导致类初始化

    private final String name = "tom";

    static {
        System.out.println("Constants class initialized!");  // 不会执行
    }

    public static String getOsName() {
        return osName;
    }

}

public class ClassLoad {
    public static void main(String[] args) {
        // 只会加载Constants类，不会初始化
        int value = Constants.COMPILE_TIME_CONSTANT;
        String msg = Constants.MESSAGE;
        // Constants.getOsName();
        // String osName = Constants.osName;

        System.out.println(Constants.class.getName());
    }
}
